package com.dzk.cp.c11x5.index;

import com.dzk.cp.c11x5.constant.C11x5Constants;
import com.dzk.cp.c11x5.constant.R5Type;
import com.dzk.cp.util.PropsUtils;

public abstract class BaseC11x5Index implements IC11x5Index {
	
	protected int code;
	
	protected int num;
	
	/**
	 * 单位：0=期，1=周期，2=天
	 */
	protected int unit;
	
	protected BaseC11x5Index() {
		num = getZQ();
		unit = 0;
	}
	
	protected BaseC11x5Index setParams(int code, int num, int unit) {
		this.code = code;
		if (num > 0) this.num = num;
		if (unit >= 0) this.unit = unit;
		return this;
	}
	
	protected int getLastestNum() {
		switch (unit) {
		case 0:
			return num;
		case 1:
			return getZQ() * num;
		case 2:
			R5Type type = R5Type.get(code);
			switch (type) {
			case SD:
				return Integer.valueOf(PropsUtils.getProperty(C11x5Constants.SD11X5_TIMES)) * num;
			case JX:
				return Integer.valueOf(PropsUtils.getProperty(C11x5Constants.JX11X5_TIMES)) * num;
			case GD:
				return Integer.valueOf(PropsUtils.getProperty(C11x5Constants.GD11X5_TIMES)) * num;
			default:
				return num;
			}
		default:
			return num;
		}
	}
	
	protected abstract int getZQ();

}
